package com.gjzt.business.publish.listener;

import java.util.Date;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.runtime.ProcessInstance;

import com.eastdigit.bpm.service.FormFactory;
import com.eastdigit.system.service.SpringServiceFactory;
import com.gjzt.business.publish.inter.PublishBillMapper;
import com.gjzt.business.publish.model.PublishBill;

public class AuditListener implements TaskListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4245799204542353538L;

	@Override
	public void notify(DelegateTask delegateTask){
		String processInstanceId = delegateTask.getProcessInstanceId();
		ProcessInstance processInstance = delegateTask.getExecution().getEngineServices()
				.getRuntimeService().createProcessInstanceQuery()
				.processInstanceId(processInstanceId).singleResult();
		String businessKey = processInstance.getBusinessKey();
		
		PublishBillMapper publishBillMapper = (PublishBillMapper)SpringServiceFactory.getBean("publishBillMapper");
		
		String comment = (String)delegateTask.getVariableLocal("comment");
		
		PublishBill publishBill = new PublishBill();
    	publishBill.setBillId(FormFactory.getBusinessId(businessKey));
    	publishBill.setComment(comment);
    	publishBill.setApplyTime(new Date());
    	publishBill.setAuditor(Authentication.getAuthenticatedUserId());
    	publishBillMapper.updateByPrimaryKeySelective(publishBill);

	}

}
